/*
 * StartWindow.java
 *
 * Created on 10. říjen 2008, 14:38
 */

package gui;

import interfaces.Core_Events;

/**
 *
 * @author  Groš
 */
public class StartWindow extends javax.swing.JFrame {

    /** Creates new form StartWindow */
    public StartWindow(Core_Events event) {
        setSystemLook();
        initComponents();
        setRB();
        this.event = event;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        skupina = new javax.swing.ButtonGroup();
        popisek = new javax.swing.JLabel();
        rbClient = new javax.swing.JRadioButton();
        rbServer = new javax.swing.JRadioButton();
        bCancel = new javax.swing.JButton();
        bOK = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Start");
        setResizable(false);

        popisek.setText("Start:");

        rbClient.setText("Client");

        rbServer.setText("Server");

        bCancel.setText("Cancel");
        bCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelActionPerformed(evt);
            }
        });

        bOK.setText("OK");
        bOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bOKActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(popisek)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rbClient))
                    .addComponent(bOK))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bCancel)
                    .addComponent(rbServer))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(popisek)
                    .addComponent(rbClient)
                    .addComponent(rbServer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bCancel)
                    .addComponent(bOK))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
private void setRB(){
        skupina.add(rbClient);
        skupina.add(rbServer);
        skupina.clearSelection();
}

private void setSystemLook() {
    try {
      javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
    } 
    catch(Exception e) {
      System.out.println("Error setting native look: " + e);
    }
    this.setVisible(true);
}

private void bCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelActionPerformed
    this.dispose();
}//GEN-LAST:event_bCancelActionPerformed

private void bOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bOKActionPerformed
    event.core_message("StW:OK");
}//GEN-LAST:event_bOKActionPerformed

/** for server gets "server" 
 *  for client gets "client"
 *  for nothing gets "none"
 */
public String getSelectedRB() {
    if (rbClient.isSelected()) return "client";
    if (rbServer.isSelected()) return "server";
    return "none";
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancel;
    private javax.swing.JButton bOK;
    private javax.swing.JLabel popisek;
    private javax.swing.JRadioButton rbClient;
    private javax.swing.JRadioButton rbServer;
    private javax.swing.ButtonGroup skupina;
    // End of variables declaration//GEN-END:variables
    private Core_Events event;
}
